<?php
/**
 * @author Tuong Tran <tuong.tran@outlook.com>
 */
$this->breadcrumbs = array(
    'Manage resource'
);
?>
<ul class="nav nav-tabs">
    <li class="active">
        <a href="#">
            <i class="splashy-hcards"></i>
            Manage resource
        </a>
    </li>
    <li>
        <a href="<?php echo url('/resource/create', array('mode' => $this->mode)) ?>">
            <i class="splashy-document_small_upload"></i> Upload Media
        </a>
    </li>
</ul>
<div class="tab-content">
    <div class="tab-pane active" id="index">
        <form method="post" action="<?php echo url('/resource/index') ?>" id="resource-form">
            <?php
            $this->widget('bootstrap.widgets.TbGridView', array(
                'type' => 'striped bordered condensed',
                'dataProvider' => $model->search(),
                'template' => "{items}\n{pager}",
                'filter' => $model,
                'template' => "{items}\n{pager}",
                'columns' => array(
                    array(
                        'name'=>'',
                        'value'=>'CHtml::checkBox("ids[]",null,array("value"=>$data->resource_id,"id"=>"cid_".$data->resource_id, "class" => "cid"))',
                        'type'=>'raw',
                        'htmlOptions'=>array('width'=>5),
                        'filter' => false
                        //'visible'=>false,
                    ),
                    array(
                        'name' => 'resource_id',
                        'header' => 'Preview',
                        'type' => 'raw',
                        'value' => 'img($data->getThumbnailUrl())',
                        'filter' => FALSE,
                        'htmlOptions' => array(
                            'width' => 128
                        )
                    ),
                    'resource_name',
                    'resource_description',
                    array('name' => 'update_time',
                        'filter' => false,
                        'type' => 'datetime'
                    ),
                    array(
                        'class' => 'bootstrap.widgets.TbButtonColumn',
                        'template' => '{view}{update}{delete}',
                        'buttons' => array(
                            'update' => array(
                                'url' => 'url("/resource/update", array("id" => $data->resource_id, "mode" => "'.$this->mode.'"))'
                            )
                        )
                    )
                ),
            ));
            ?>

            <div class="rows form-actions">
                <input type="button" class="btn btn-link" value="Check all" id="check-all" />
                <select name="action" class="btn">
                    <option>Delete</option>
                </select>
                <input type="button" id="delete" class="btn btn-danger" value="Delete resource" />
            </div>
        </form>

    </div>
</div>
<script type="text/javascript">
    $(document).ready(function(){
        $("#check-all").click(function(){
            if($(this).hasClass("checked")){
                $(".cid").attr("checked", false);
                $(this).val("Check all").removeClass("checked");
            }else{
                $(".cid").attr("checked", true);
                $(this).val("Uncheck").addClass("checked");
            }

            return false;
        });
        $("#delete").click(function(){
            if(confirm("Are you sure?")){
                $("#resource-form").submit();
            }

            return false;
        });

        $(".view").click(function(){
            return false;
        });
    });
</script>